home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_02 / nonport / winprint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  3.2 KB  |  150 lines

  1. #ifndef NO_MEMORY_H
  2. #define    CURSES_LIBRARY    1
  3. #endif
  4. #include <curses.h>
  5. #undef    winPDC_print
  6.  
  7. #ifdef PDCDEBUG
  8. char *rcsid_winprint = "$Header: C:\CURSES\nonport\RCS\winprint.c 2.1 1993/06/18 20:22:06 MH Rel MH $";
  9. #endif
  10.  
  11.  
  12.  
  13.  
  14. #define PRINT    0
  15. #define INIT    1
  16. #define READ    2
  17.  
  18. /*man-start*********************************************************************
  19.  
  20.   win_print()    - print contents of window to LPT1
  21.  
  22.   PDCurses Description:
  23.      Prints the contents of the passed window or pad to LPT1:.  All
  24.      attributes are ignored.     Newlines will be appended to the end
  25.      of all win->_y[]s.  The caller must supply the compiler-
  26.      dependent port number.
  27.  
  28.   PDCurses Return Value:
  29.      Return Status:    bit 0    0x01    Device Time Out
  30.              bit 1    0x02    Bad WINDOW* passed
  31.              bit 2    0x04    Unable to malloc memory
  32.              bit 3    0x08    I/O Error
  33.              bit 4    0x10    Selected
  34.              bit 5    0x20    Out of paper
  35.              bit 6    0x40    Acknowledge
  36.              bit 7    0x80    Not Busy
  37.  
  38.      A return value of 0 indicates success.
  39.  
  40.   PDCurses Errors:
  41.      It is an error to pass a NULL WINDOW pointer.
  42.  
  43.   Portability:
  44.      PDCurses    int win_print( WINDOW* win, int port );
  45.  
  46. **man-end**********************************************************************/
  47.  
  48. int    win_print(WINDOW *win, int port)
  49. {
  50. #if    defined( DOS )
  51. extern    void*    (*mallc)();        /* ptr to some malloc(size)    */
  52. extern    void*    (*callc)();        /* ptr to some ecalloc(num,size)*/
  53. extern    void    (*fre)();        /* ptr to some free(ptr)    */
  54.     char   *text;
  55.     int    i;
  56.     int    j;
  57.     int    status;
  58.     int    retry = 0;
  59. #endif
  60.  
  61. #ifdef PDCDEBUG
  62.     if (trace_on) PDC_debug("win_print() - called\n");
  63. #endif
  64.  
  65. #if    defined( DOS )
  66.     if (win == (WINDOW *)NULL)
  67.         return( 0x02 );
  68.  
  69.     status = PDC_print(READ, 0, port);
  70.  
  71.     if (((status & 0x20) != 0) || ((status & 0x08) != 0))
  72.         return( status );
  73.     /*
  74.      * Print the window title First
  75.      */
  76.     text = win->_title;
  77.     while (text != (char *)NULL)
  78.     {
  79.         status = PDC_print(PRINT, (int) *text, port);
  80.         while ((status & 0x80) == 0x00)
  81.         {
  82.             if ((status & 0x01) == 0x01)
  83.             {
  84.                 retry++;
  85.                 if (retry > 10)
  86.                     return( status );
  87.             }
  88.             if (((status & 0x20) == 0x20) ||
  89.                 ((status & 0x10) == 0x00) ||
  90.                 ((status & 0x08) == 0x08))
  91.             {
  92.                 return( status );
  93.             }
  94.             status = PDC_print(READ, 0, port);
  95.         }
  96.     }
  97.     PDC_print(PRINT, '\r', port);
  98.     PDC_print(PRINT, '\n', port);
  99.     PDC_print(PRINT, '\n', port);
  100.     text = (*mallc)(win->_maxx);
  101.     if (text != (char *)NULL)
  102.     {
  103.         for (i = 0; i < win->_maxy; i++)
  104.         {
  105.             for (j = 0; j < win->_maxx; j++)
  106.             {
  107.                 status = PDC_print(PRINT, (int) win->_y[i][j], port);
  108.                 while ((status & 0x80) == 0x00)
  109.                 {
  110.                     if ((status & 0x01) == 0x01)
  111.                     {
  112.                         retry++;
  113.                         if (retry > 10)
  114.                         {
  115.                             (*fre)(text);
  116.                             return( status );
  117.                         }
  118.                     }
  119.                     if (((status & 0x20) == 0x20) ||
  120.                         ((status & 0x10) == 0x00) ||
  121.                         ((status & 0x08) == 0x08))
  122.                     {
  123.                         (*fre)(text);
  124.                         return( status );
  125.                     }
  126.  
  127.                     status = PDC_print(READ, 0, port);
  128.                 }
  129.                 retry = 0;
  130.  
  131.             }
  132.             PDC_print(PRINT, '\r', port);
  133.             PDC_print(PRINT, '\n', port);
  134.         }
  135.         PDC_print(PRINT, '\f', port);
  136.         (*fre)(text);
  137.         return( 0x00 );
  138.     }
  139.     return( 0x04 );
  140. #endif
  141.  
  142. #if    defined( HC ) && defined( FLEXOS )
  143.     return( 0x03 );
  144. #endif
  145.  
  146. #ifdef OS2
  147.     return( 0x03 );
  148. #endif
  149. }
  150.